home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 …SCII & the Runetime Code / ADC Developer CD (1992-07) (''Butch ASCII And The Runtime Code'')_iso / Dev.CD 199207.iso / Development Platforms / LISP Related / MCL Networking / Network / SAMPLE-SESSION.TXT < prev   
Encoding:
Text File  |  1990-09-04  |  6.0 KB  |  154 lines  |  [TEXT/CCL ]

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;; Copyright 1987, 1988, 1989, 1990 by Ruben Kleiman for Apple Computer, Inc.
  3. ;;; Advanced Technology Group
  4. ;;;
  5.  
  6. ;;;
  7. ;;; This package allows you to communicate among Macintoshes using AppleTalk's
  8. ;;; ADSP (Asynchronous Data Stream Protocol) protocol.  It also allows you
  9. ;;; to use AppleTalk name service NBP (Name Binding Protocol) protocol.
  10. ;;;
  11.  
  12.  
  13. ;;; Sample Networking Session
  14. ;;;
  15. ;;; Sample session between two virtual Mac's: MAC1 and MAC2
  16. ;;; You can emulate this session by entering the following forms into
  17. ;;; your Lisp listener.  The prompts MAC1> and MAC2> designate
  18. ;;; the "virtual" Mac into whose listener you are theoretically typing.
  19. ;;; Note that we use AppleTalk's ability to send messages WITHIN a Macintosh
  20. ;;; to do this sample session.
  21. ;;;
  22. ;;; We will type forms into the Listener (within the :NETWORK package)
  23. ;;; which will show you how to processes in two machines can communicate
  24. ;;; with each other.  The variable NETWORK::*MONITORING*, when set to a
  25. ;;; NON-NIL value, will cause monitoring information to be printed in
  26. ;;; your listener in response to some functions you may use (e.g., the ones
  27. ;;; that try to set up a connection).  You may set this variable to NIL 
  28. ;;; to prevent these messages from being printed.
  29. ;;;
  30. ;;; The general server/client architecture is as follows:  you can create
  31. ;;; an object within your machine which acts as a server.  A server, once
  32. ;;; created, registers itself in the network.  You can create one or more
  33. ;;; client objects in other (or the same) machines, specifying which server
  34. ;;; each client object should be assumed to be connected with.  The function
  35. ;;; TURN-SERVER-ON and TURN-CLIENT-ON are used to do this.  Once a server
  36. ;;; or client object is successfully created, a connection between them
  37. ;;; is also automatically available.  We call "partners" to be a server which is connected
  38. ;;; to a client: i.e., the server and client objects are said to be partners.
  39. ;;; Once a connection is established, the communications protocol is balanced:
  40. ;;; i.e., the server and clients have equal communications rights.  It is possible
  41. ;;; to send and queue up multiple messages in either direction, or to send
  42. ;;; messages simultaneously in both directions.
  43. ;;;
  44.  
  45. ;;;
  46. ;;; Partners communicate with each other via stream messages sent to the appropiate
  47. ;;; objects: e.g., (format client "Hello") will send the string "Hello" to the
  48. ;;; machine in which the client object is defined.  It is important, however,
  49. ;;; the you use the FORCE-OUTPUT function to actually cause the message to
  50. ;;; be sent to the remote client or server.  This allows you to internally
  51. ;;; queue up multiple messages before sending them.
  52. ;;;
  53.  
  54.  
  55.  
  56. ? (require :adsp)      ; THIS LOADS THE NECESSARY FUNCTIONS
  57. ;Loading "Big Disk:Hacking:Programming:Allegro Lisp:Network:ADSP.lisp"...
  58. ;Loading "Big Disk:Hacking:Programming:Allegro Lisp:Library:TRAPS.fasl"...
  59. ;Loading "Big Disk:Hacking:Programming:Allegro Lisp:Network:NETWORK-DEFS.fasl"...
  60. ;Loading "Big Disk:Hacking:Programming:Allegro Lisp:Network:DRIVER.fasl"...
  61. ;Loading "Big Disk:Hacking:Programming:Allegro Lisp:Network:NBP.fasl"...
  62. ;Loading "Big Disk:Hacking:Programming:Allegro Lisp:Servers:SERVER.fasl"...
  63. ;Loading "Big Disk:Hacking:Programming:Allegro Lisp:Events:EVENT.fasl"...
  64. "ADSP"
  65.  
  66. ? (in-package :network)    ; MAKE SURE YOU EVALUATE THIS ONE IN THE LISTENER WINDOW!!!
  67. #<PACKAGE "NETWORK">
  68.  
  69. MAC1> (init-adsp)          ; THIS INITIALIZES THE ADSP DRIVER
  70. T
  71. ;;; THE FOLLOWING FORM IS USED TO CREATE A SERVER NAMED "Ruben" WHOSE TYPE IS "Cool Dudes"
  72. ;;; THE SERVER COMMUNICATIONS MEDIUM IS SPECIFIED TO BE :ADSP (THE ONLY ONE CURRENTLY
  73. ;;; AVAILABLE IN THIS PACKAGE--YOU CAN WRITE YOUR OWN EXTENSIONS, E.G., TCP/IP, AND
  74. ;;; ADD THEM TO THIS SIMPLE SERVER ARCHITECTURE).  THIS SERVER NOW EXISTS IN
  75. ;;; THE MAC1 MACINTOSH.
  76. MAC1> (turn-server-on :adsp :name "Ruben" :type "Cool Dudes")
  77.  
  78. adsp server initialized on #<Object #169, a *ADSP-SERVER*>
  79. adsp server stream opened on #<Object #169, a *ADSP-SERVER*>
  80. #<Object #169, a *ADSP-SERVER*>
  81.  
  82. ;;; THE FOLLOWING FORM CREATES A CLIENT IN THE MACINTOSH MAC2 FOR THE SERVER WE
  83. ;;; JUST CREATED IN MAC1.  THE VARIABLE server IS HERE BOUND TO AN OBJECT WHICH STANDS
  84. ;;; FOR THE REMOTE SERVER: THAT IS, WE CAN TREAT server AS IF IT WERE THE REMOTE SERVER.
  85. ;;; WE WILL LATER USE server TO SEND MESSAGES TO THAT SERVER.
  86. MAC2> (turn-client-on server :adsp :server-name "Ruben" :server-type "Cool Dudes")
  87.  
  88. adsp stream initialized on #<Object #176, a *ADSP-STREAM*>
  89. adsp stream connection requested on #<Object #176, a *ADSP-STREAM*>
  90. adsp st
  91. adsp stream initialized on #<Object #177, a *ADSP-STREAM*>
  92. adsp stream opened on #<Object #177, a *ADSP-STREAM*>
  93. About to accept conn
  94. adsp stream connection accepted on #<Object #177, a *ADSP-STREAM*>ream opened on #<Objec
  95. t #176, a *ADSP-STREAM*>
  96. NIL
  97.  
  98. MAC2>  server
  99. #<Object #176, a *ADSP-STREAM*>
  100.  
  101. ;;; LET'S GET SERVER STATUS INFORMATION.  THIS TELLS YOU WHETHER THE CONNECTION
  102. ;;; IS OPEN OR NOT, AND HOW MUCH SPACE IS ALLOCATED IN THE OUTGOING AND INCOMING
  103. ;;; MESSAGE QUEUES AS WELL AS HOW MUCH OF IT IS USED UP.  (FOR THOSE WHO NEED
  104. ;;; TO KNOW, THIS INFORMATION IS THE ONE RETURNED BY THE ADSP DRIVER'S STATUS CALL
  105. ;;; AND IS DESCRIBED IN DETAIL IN THE ADSP PROGRAMMER'S MANUAL.)
  106. MAC2> (ask server (status))
  107. OPEN
  108. 0
  109. 30634
  110. 0
  111. 30634
  112.  
  113. MAC1> (setq client (get-new-client :server-name "Ruben" :server-type "Cool Dudes"))
  114. #<Object #177, a *ADSP-STREAM*>
  115.  
  116. MAC1> (ask client (status))
  117. OPEN
  118. 0
  119. 30634
  120. 0
  121. 30634
  122.  
  123. ;;; Now let's send something from MAC1 to MAC2
  124.  
  125. MAC1> (listen client)    ; nothing pending to receive in MAC2
  126. NIL
  127.  
  128. MAC2> (write-line "Hello MAC1!" server)
  129. "Hello MAC1!"
  130. MAC2> (force-output server)       ; force buffer out to MAC1
  131. NIL
  132.  
  133. MAC1> (listen client)
  134. T                                ; something has arrived at MAC1
  135.  
  136. MAC1> (read-line client)
  137. "Hello MAC1!"
  138. NIL
  139.  
  140. ;;; Now let's send something to MAC2
  141.  
  142. MAC1> (write-string "Well, hello MAC2" client)
  143. Well, hello MAC2
  144. MAC1> (force-output client)
  145. NIL
  146.  
  147.  
  148. MAC2> (listen server)
  149. T
  150. MAC2> (read-line server)
  151. "Well, hello MAC2"
  152. T
  153.  
  154.